//
//  MPTaskStatusView.m
//  MarkPlatform
//
//  Created by xiao6 on 2017/12/30.
//  Copyright © 2017年 AT. All rights reserved.
//

#import "MPTaskStatusView.h"

@interface MPTaskStatusView()
@property (weak, nonatomic) IBOutlet MPAppButton *rightButton;
@property (weak, nonatomic) IBOutlet UIButton *statusButton;

@end

@implementation MPTaskStatusView

- (IBAction)clickRightButton:(id)sender {
    if (self.model.status == MPMarkStateFail) {// 审核不通过
        // 申诉
        if ([self.delegate respondsToSelector:@selector(taskStatusViewDidClickAppealButton)]) {
            [self.delegate taskStatusViewDidClickAppealButton];
        }
    }
    else if (self.model.status == MPMarkStateAppealing){// 申诉中
        // 取消
        if ([self.delegate respondsToSelector:@selector(taskStatusViewDidClickCancelButton)]) {
            [self.delegate taskStatusViewDidClickCancelButton];
        }
    }
}

- (void)setModel:(MPTaskModel *)model {
    _model = model;
    switch (_model.status) {
        case MPMarkStateSuccess:// 任务成功
            self.rightButton.hidden = YES;
            [self.statusButton setTitle:@"任务成功!" forState:UIControlStateNormal];
            [self.statusButton setTitleColor:[UIColor colorWithRGB:0x4CD94A] forState:UIControlStateNormal];
            [self.statusButton setImage:[UIImage imageNamed:@"icon_renwuwancheng"] forState:UIControlStateNormal];
            break;
        case MPMarkStateFail:// 审核不通过
            self.rightButton.hidden = NO;
            [self.statusButton setTitle:@"审核不通过" forState:UIControlStateNormal];
            [self.statusButton setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
            [self.statusButton setImage:nil forState:UIControlStateNormal];
            [self.rightButton setTitle:@"申诉" forState:UIControlStateNormal];
            self.rightButton.enabled = self.model.appeal;
            break;
        case MPMarkStateAppealing:// 任务申诉中
            self.rightButton.hidden = NO;
            [self.statusButton setTitle: @"任务申诉中" forState:UIControlStateNormal];
            [self.statusButton setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
            [self.statusButton setImage:nil forState:UIControlStateNormal];
            [self.rightButton setTitle:@"取消" forState:UIControlStateNormal];
            self.rightButton.enabled = self.model.cancel;
            break;
        case MPMarkStateCanceled:// 任务已取消
            self.rightButton.hidden = YES;
            [self.statusButton setTitle:@"任务已取消" forState:UIControlStateNormal];
            [self.statusButton setTitleColor:[UIColor colorWithRGB:0x333333] forState:UIControlStateNormal];
            [self.statusButton setImage:nil forState:UIControlStateNormal];
            break;
        case MPMarkStateReviewing:// 任务待审核
            self.rightButton.hidden = YES;
            [self.statusButton setTitle:@"任务待审核" forState:UIControlStateNormal];
            [self.statusButton setTitleColor:[UIColor colorWithRGB:0x333333] forState:UIControlStateNormal];
            [self.statusButton setImage:nil forState:UIControlStateNormal];
            break;
            
        default:
            break;
    }
}

@end
